package com.fly.lambda.framework.context;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Fly on 2016/7/14.
 */
public class ContextHolder {

    private static final ThreadLocal<Map<String, String>> holder = new ThreadLocal<Map<String, String>>();

    private static void set(String name, String value){
        getContextMap().put(name, value);
    }

    private static String get(String name){
        return getContextMap().get(name);
    }

    private static Map<String, String> getContextMap(){
        Map<String, String> map = holder.get();
        if (null == map){
            map = new HashMap<String, String>();
            holder.set(map);
        }
        return map;
    }

    private static final String accountId = "ACCOUNT_ID";   //账号id

    public static String getAccountId(){
        return get(accountId);
    }

    public static void setAccountId(String value){
        set(accountId, value);
    }
}
